﻿using Grpc.Net.Client.Balancer;
using Microsoft.Extensions.Configuration;
using Nacos.AspNetCore.V2;
using Nacos.Provider.gRPC;
using Nacos.V2;
using Nacos.V2.Naming;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class NacosGrpcChannelServiceCollectionExtensions
    {
        public static IServiceCollection AddNacosAspNetWithGrpcClient(this IServiceCollection services, IConfiguration configuration, Action<NacosGrpcChannelOptions> options = null, string section = "nacos")
        {
            services.AddSingleton<ResolverFactory, NacosResolverFactory>();
            services.AddSingleton<LoadBalancerFactory, NacosRandomBalancerFactory>();

            services.AddNacosAspNet(configuration, section);
            services.Configure<NacosGrpcChannelOptions>(options);
            services.AddTransient<INacosGrpcChannel, NacosGrpcChannel>();
            return services;
        }
    }
}
